package com.zwr.normal;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CountDownDemo {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(3);
        ExecutorService service = Executors.newFixedThreadPool(4);
        service.submit(() -> {
//            log.debug("begin...");
//            sleep(1);
//            latch.countDown();
//            log.debug("end...{}", latch.getCount());
        });
        service.submit(() -> {
//            log.debug("begin...");
//            sleep(1.5);
            latch.countDown();
//            log.debug("end...{}", latch.getCount());
        });
        service.submit(() -> {
//            log.debug("begin...");
//            sleep(2);
            latch.countDown();
//            log.debug("end...{}", latch.getCount());
        });
        service.submit(()->{
            try {
//                log.debug("waiting...");
                latch.await();
//                log.debug("wait end...");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
    }
}
